package leetcode.动态规划和贪心;

import java.util.Arrays;

public class Test300最长上升子序列 {

    public static int lengthOfLIS(int[] nums) {
        // 数组是空的，没有序列可找
        int n = nums.length;
        if (n == 0)
            return 0;
        // dp[i] 表示以 i 结尾的子序列的最长上升长度
        int[] dp = new int[n];
        Arrays.fill(dp, 1);

        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[j] < nums[i])
                    dp[i] = Math.max(dp[i], 1 + dp[j]);
            }
        }
        int res = 1;
        for (int i = 0; i < dp.length; i++) {
            res = Math.max(res, dp[i]);
        }
        return res;
    }

    public static void main(String[] args) {
        int[] nums = {10,9,2,5,3,7,101,18};
        System.out.println(lengthOfLIS(nums));
    }
}
